import enum
import datetime
import typing as tp

import pydantic


# 执行器配置


class ExecutorType(enum.StrEnum):
    cmd = "cmd"
    bash = "bash"
    builtin_py_func = "builtin_py_func"
    reboot = "reboot"


class Executor(pydantic.BaseModel):
    type: ExecutorType  # ExecutorType
    args: tp.List[str] = []
    kwargs: tp.Dict[str, tp.Union[int, float, str]] = {}

    timeout: tp.Optional[int] = None  # sec

    def __str__(self):
        return f"<{self.type}> <args: {self.args}, kwargs: {self.kwargs}, timeout: {self.timeout}>"


# 节点配置
SELF_NODE = "127.0.0.1"


class Node(pydantic.BaseModel):
    ip4: str = SELF_NODE


# scheduler 配置


class APSDate(pydantic.BaseModel):
    run_date: tp.Optional[datetime.datetime] = None


class APSInterval(pydantic.BaseModel):
    weeks: float = 0
    days: float = 0
    hours: float = 0
    minutes: float = 0
    seconds: float = 0


class APSCorn(pydantic.BaseModel):
    year: float = 0
    month: float = 0
    day: float = 0
    week: float = 0
    day_of_week: float = 0
    hour: float = 0
    minute: float = 0
    second: float = 0


class APSCfg(pydantic.BaseModel):
    type: tp.Literal["date", "interval", "cron"]

    date: APSDate = APSDate()
    interval: APSInterval = APSInterval()
    corn: APSCorn = APSCorn()

    start_date: tp.Optional[datetime.datetime] = None
    end_date: tp.Optional[datetime.datetime] = None


class JobType(enum.StrEnum):
    snsm = "单节点单模块"
